package com.sc.byahi.user.shared;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

//import javax.persistence.Id;
//import javax.persistence.Transient;

import com.sc.byahi.user.shared.constants.Config;

public class SearchBean extends AbstractEntity<Long> {
	private static final long serialVersionUID = 1L;
//	@Id
	protected Long id = null;

	// Non display parameters
	// Long because JSON converts it in Long
	private Long ratingThreshold = Config.NO_RATING;

	private Long ageBegin = null;
	private Long ageEnd = null;
	private Long heightBegin = null;
	private Long heightEnd = null;

	private String gender = "";// never empty
	private String physicalStatus = "";
	private String religion = "";
	private String motherTongue = "";
	private String manglik = ""; // Yes No

	private List<String> maritalStatus = new ArrayList<String>();
	private List<String> caste = new ArrayList<String>();
	private List<String> degrees = new ArrayList<String>();
	private List<String> languages = new ArrayList<String>();
	private List<String> eatingHabits = new ArrayList<String>();
	private List<String> locationCountry = new ArrayList<String>();
	private List<String> employmentType = new ArrayList<String>();

	// For saved searches
	private String owner = "";
	private String name = "";

	public static final String AGE_BEGIN = 			"ageBegin";            
	public static final String AGE_END = 			"ageEnd";               
	public static final String CASTE = 			"caste";                  
	public static final String DEGREES = 			"degrees";              
	public static final String EATING_HABITS = 		"eatingHabits";        
	public static final String EMPLOYMENT_TYPE = 	"employmentType"; 
	public static final String GENDER =			"gender";                
	public static final String HEIGHT_BEGIN = 		"heightBegin";         
	public static final String HEIGHT_END = 		"heightEnd";            
	public static final String LANGUAGES = 		"languages";           
	public static final String LOCATION_COUNTRY = 	"locationCountry";   
	public static final String MANGLIK = 			"manglik";              
	public static final String MARITAL_STATUS = 	"maritalStatus";       
	public static final String MOTHER_TONGUE = 	"motherTongue";     
	public static final String ONLY_UNRATED = 		"onlyUnrated" ;         
	public static final String PHYSICAL_STATUS = 	"physicalStatus";     
	public static final String RATING_THRESHOLD = 	"ratingThreshold";   
	public static final String RELIGION = 			"religion";               	
	
	public static final String OWNER = "owner";
	public static final String NAME = "name";

	// Only for admin
	
	private transient Boolean upapproved = false;

	public void setDefaults() {
		setRatingThreshold(Config.NO_RATING);

		setAgeBegin(Config.DEFAULT_AGE_BEGIN);
		setAgeEnd(Config.DEFAULT_AGE_END);
		setHeightBegin(60l);
		setHeightEnd(72l);

		setGender("Female");
		setPhysicalStatus("Normal");
		setReligion("Hindu");
		setMaritalStatus(Arrays.asList("Unmarried"));
		setLocationCountry(Arrays.asList("India"));
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("name=").append(getName()).append(",\n");
		sb.append("gender=").append(getGender()).append(",\n");
		sb.append("ageBegin=").append(getAgeBegin()).append(",\n");
		sb.append("ageEnd=").append(getAgeEnd()).append(",\n");
		sb.append("heightBegin=").append(getHeightBegin()).append(",\n");
		sb.append("heightEnd=").append(getHeightEnd()).append(",\n");
		sb.append("physicalStatus=").append(getPhysicalStatus()).append(",\n");
		sb.append("maritalStatus=").append(getMaritalStatus()).append(",\n");
		sb.append("degrees=").append(getDegrees()).append(",\n");
		sb.append("religion=").append(getReligion()).append(",\n");
		sb.append("caste=").append(getCaste()).append(",\n");
		sb.append("motherTongue=").append(getMotherTongue()).append(",\n");
		sb.append("languages=").append(getLanguages()).append(",\n");
		sb.append("eatingHabits=").append(getEatingHabits()).append(",\n");
		sb.append("manglik=").append(getManglik()).append(",\n");
		// sb.append("passport=").append(getPassport()).append(",\n");
		sb.append("locationCountry=").append(getLocationCountry()).append(",\n");
		sb.append("employmentType=").append(getEmploymentType()).append(",\n");
		sb.append("ratingThreshold=").append(getRatingThreshold()).append(",\n");
		return sb.toString();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void fromString(String str) {
	}

	@Override
	public List<String> getUnindexedPropertyNames() {
		List<String> props = new ArrayList<String>();
		props.add(GENDER);
		props.add(AGE_BEGIN);
		props.add(AGE_END);
		props.add(HEIGHT_BEGIN);
		props.add(HEIGHT_END);
		props.add(PHYSICAL_STATUS);
		props.add(MARITAL_STATUS);
		props.add(DEGREES);
		props.add(RELIGION);
		props.add(CASTE);
		props.add(MOTHER_TONGUE);
		props.add(LANGUAGES);
		props.add(EATING_HABITS);
		props.add(MANGLIK);
		props.add(LOCATION_COUNTRY);
		props.add(EMPLOYMENT_TYPE);

		props.add(RATING_THRESHOLD);
		props.add(ONLY_UNRATED);
		return props;

	}

	@Override
	public List<String> getIndexedPropertyNames() {
		List<String> props = new ArrayList<String>();
		props.add(NAME);
		props.add(OWNER);
		return props;

	}

	public Object getProperty(String key) {
		if (NAME.equals(key)) {
			return getName();
		}
		if (GENDER.equals(key)) {
			return getGender();
		}
		if (AGE_BEGIN.equals(key)) {
			return getAgeBegin();
		}
		if (AGE_END.equals(key)) {
			return getAgeEnd();
		}
		if (HEIGHT_BEGIN.equals(key)) {
			return getHeightBegin();
		}
		if (HEIGHT_END.equals(key)) {
			return getHeightEnd();
		}
		if (PHYSICAL_STATUS.equals(key)) {
			return getPhysicalStatus();
		}
		if (MARITAL_STATUS.equals(key)) {
			return getMaritalStatus();
		}
		if (DEGREES.equals(key)) {
			return getDegrees();
		}
		if (RELIGION.equals(key)) {
			return getReligion();
		}
		if (CASTE.equals(key)) {
			return getCaste();
		}
		if (MOTHER_TONGUE.equals(key)) {
			return getMotherTongue();
		}
		if (LANGUAGES.equals(key)) {
			return getLanguages();
		}
		if (EATING_HABITS.equals(key)) {
			return getEatingHabits();
		}
		if (MANGLIK.equals(key)) {
			return getManglik();
		}
		if (LOCATION_COUNTRY.equals(key)) {
			return getLocationCountry();
		}
		if (EMPLOYMENT_TYPE.equals(key)) {
			return getEmploymentType();
		}
		if (OWNER.equals(key)) {
			return getOwner();
		}
		if (RATING_THRESHOLD.equals(key)) {
			return getRatingThreshold();
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	public void setProperty(String key, Object value) {
		if (NAME.equals(key)) {
			setName((String) value);
		}
		if (GENDER.equals(key)) {
			setGender((String) value);
		}
		if (AGE_BEGIN.equals(key)) {
			setAgeBegin((Long) value);
		}
		if (AGE_END.equals(key)) {
			setAgeEnd((Long) value);
		}
		if (HEIGHT_BEGIN.equals(key)) {
			setHeightBegin((Long) value);
		}
		if (HEIGHT_END.equals(key)) {
			setHeightEnd((Long) value);
		}
		if (PHYSICAL_STATUS.equals(key)) {
			setPhysicalStatus((String) value);
		}
		if (MARITAL_STATUS.equals(key)) {
			setMaritalStatus((List<String>) value);
		}
		if (DEGREES.equals(key)) {
			setDegrees((List<String>) value);
		}
		if (RELIGION.equals(key)) {
			setReligion((String) value);
		}
		if (CASTE.equals(key)) {
			setCaste((List<String>) value);
		}
		if (MOTHER_TONGUE.equals(key)) {
			setMotherTongue((String) value);
		}
		if (LANGUAGES.equals(key)) {
			setLanguages((List<String>) value);
		}
		if (EATING_HABITS.equals(key)) {
			setEatingHabits((List<String>) value);
		}

		if (MANGLIK.equals(key)) {
			setManglik((String) value);
		}
		if (LOCATION_COUNTRY.equals(key)) {
			setLocationCountry((List<String>) value);
		}
		if (EMPLOYMENT_TYPE.equals(key)) {
			setEmploymentType((List<String>) value);
		}
		if (RATING_THRESHOLD.equals(key)) {
			setRatingThreshold((Long) value);
		}
		if (OWNER.equals(key)) {
			setOwner((String) value);
		}

	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		if (id != null) {
			this.id = id;
		}
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		if (gender != null)
			this.gender = gender;
	}

	public Long getAgeBegin() {
		return ageBegin;
	}

	/**
	 * Not checked for NULL deliberately
	 * 
	 * @param ageBegin
	 */
	public void setAgeBegin(Long ageBegin) {
		this.ageBegin = ageBegin;
	}

	public Long getAgeEnd() {
		return ageEnd;
	}

	/**
	 * Not checked for NULL deliberately
	 * 
	 * @param ageBegin
	 */
	public void setAgeEnd(Long ageEnd) {
		this.ageEnd = ageEnd;
	}

	public Long getHeightBegin() {
		return heightBegin;
	}

	public void setHeightBegin(Long heightBegin) {
		if (heightBegin != null)
			this.heightBegin = heightBegin;
	}

	public Long getHeightEnd() {
		return heightEnd;
	}

	public void setHeightEnd(Long heightEnd) {
		if (heightEnd != null)
			this.heightEnd = heightEnd;
	}

	public String getPhysicalStatus() {
		return physicalStatus;
	}

	public void setPhysicalStatus(String physicalStatus) {
		if (physicalStatus != null) {
			this.physicalStatus = physicalStatus;
		}
	}

	public List<String> getMaritalStatus() {
		return maritalStatus;
	}

	public void setMaritalStatus(List<String> maritalStatus) {
		if (maritalStatus != null) {
			this.maritalStatus.clear();
			this.maritalStatus.addAll(maritalStatus);
		}
	}

	public List<String> getDegrees() {
		return degrees;
	}

	public void setDegrees(List<String> degrees) {
		if (degrees != null) {
			this.degrees.clear();
			this.degrees.addAll(degrees);
		}
	}

	public String getReligion() {
		return religion;
	}

	public void setReligion(String religion) {
		if (religion != null) {
			this.religion = religion;
		}
	}

	public List<String> getCaste() {
		return caste;
	}

	public void setCaste(List<String> caste) {
		if (caste != null) {
			this.caste.clear();
			this.caste.addAll(caste);
		}

	}

	public String getMotherTongue() {
		return motherTongue;
	}

	public void setMotherTongue(String motherTongue) {
		if (motherTongue != null) {
			this.motherTongue = motherTongue;
		}
	}

	public List<String> getLanguages() {
		return languages;
	}

	public void setLanguages(List<String> languages) {
		if (languages != null) {
			this.languages.clear();
			this.languages.addAll(languages);
		}

	}

	public List<String> getEatingHabits() {
		return eatingHabits;
	}

	public void setEatingHabits(List<String> eatingHabits) {
		if (eatingHabits != null) {
			this.eatingHabits.clear();
			this.eatingHabits.addAll(eatingHabits);
		}

	}

	public String getManglik() {
		return manglik;
	}

	public void setManglik(String manglik) {
		if (manglik != null) {
			this.manglik = manglik;
		}
	}

	public List<String> getLocationCountry() {
		return locationCountry;
	}

	public void setLocationCountry(List<String> locationCountry) {
		if (locationCountry != null) {
			this.locationCountry.clear();
			this.locationCountry.addAll(locationCountry);
		}

	}

	public List<String> getEmploymentType() {
		return employmentType;
	}

	public void setEmploymentType(List<String> employmentType) {
		if (employmentType != null) {
			this.employmentType.clear();
			this.employmentType.addAll(employmentType);
		}

	}

	public Long getRatingThreshold() {
		return ratingThreshold;
	}

	public void setRatingThreshold(Long ratingThreshold) {
		this.ratingThreshold = ratingThreshold;
	}

	public Boolean getUnapproved() {
		return upapproved;
	}

	public void setUnapproved(Boolean unapproved) {
		if (unapproved != null)
			this.upapproved = unapproved;
	}

	public String getOwner() {
		return owner;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}
}
